//package com.c4p.config;
//
//import org.springframework.security.authorization.AuthorizationDecision;
//import org.springframework.security.authorization.ReactiveAuthorizationManager;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.oauth2.provider.OAuth2Authentication;
//import org.springframework.security.web.server.authorization.AuthorizationContext;
//import org.springframework.stereotype.Component;
//import org.springframework.util.AntPathMatcher;
//import org.springframework.util.StringUtils;
//import reactor.core.publisher.Mono;
//
//import java.util.concurrent.ConcurrentSkipListSet;
//
//@Component
//public class AccessManager implements ReactiveAuthorizationManager<AuthorizationContext> {
//    private ConcurrentSkipListSet<String> permitAll = new ConcurrentSkipListSet<>();
//    private static final AntPathMatcher antPathMatcher = new AntPathMatcher();
//
//    public AccessManager() {
//        permitAll.add("/**/oauth/**");
//    }
//
//    @Override
//    public Mono<AuthorizationDecision> check(Mono<Authentication> authentication, AuthorizationContext context) {
//        return authentication.map(auth -> {
//            if (checkPath(context.getExchange().getRequest().getURI().getPath())){
//                return new AuthorizationDecision(Boolean.TRUE);
//            }
//            if (auth instanceof OAuth2Authentication){
//                OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) auth;
//                String clientId = oAuth2Authentication.getOAuth2Request().getClientId();
//                if (!StringUtils.isEmpty(clientId)){
//                    return new AuthorizationDecision(Boolean.TRUE);
//                }
//            }
//            return new AuthorizationDecision(Boolean.FALSE);
//        });
//    }
//
//
//    public Boolean checkPath(String url){
//        return permitAll.stream().anyMatch(p -> antPathMatcher.match(p, url));
//    }
//
//}
